import { request } from '@/utils/request'
import type {
  User,
  Type,
  ValidateCode,
  UserInfo,
  PatientList,
  Patient
} from '@/types/user'

// 密码登录接口
export const loginByPasswordAPI = (mobile: string, password: string) => {
  return request<User>('/login/password', 'POST', {
    mobile,
    password
  })
}

// 验证码登录接口
export const loginByCodeAPI = (mobile: string, code: string) => {
  return request<User>('/login', 'POST', {
    mobile,
    code
  })
}

// 获取短信验证码
export const getMobileCode = (mobile: string, type: Type) => {
  return request<ValidateCode>('/code', 'GET', {
    mobile,
    type
  })
}

// 通过QQ登录
export const loginByQQAPI = (openId: string, source: string) => {
  return request<User>('/login/thirdparty', 'POST', {
    openId,
    source
  })
}

// 绑定手机号
export const bindMobileAPI = (mobile: string, code: string, openId: string) => {
  return request<User>('/login/binding', 'POST', {
    mobile,
    code,
    openId
  })
}

// 获取用户信息
export const getUserInfoAPI = () => {
  return request<UserInfo>('/patient/myUser')
}

// 获取患者列表信息
export const getPatientListAPI = () => {
  return request<PatientList>('/patient/mylist')
}

// 添加患者
export const addPatientAPI = (patient: Patient) => {
  return request('/patient/add', 'POST', patient)
}

// 编辑患者
export const updatePatientAPI = (patient: Patient) => {
  return request('/patient/update', 'PUT', patient)
}

// 删除患者
export const delPatientAPI = (id: string) => {
  return request(`/patient/del/${id}`, 'DELETE')
}

// 获取未读消息数量
export const getUnreadMsgCountAPI = () => {
  return request<number>('/patient/message/unRead/all')
}
